package com.mingqijia.gassafety.shared.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName DeviceType.java
 * @Description TODO
 * @createTime 2023年06月28日
 */
@Getter
@RequiredArgsConstructor
public enum DeviceType {

    DEVICE_TYPE_1("一键呼救",1),
    DEVICE_TYPE_2("水浸报警器",2),
    DEVICE_TYPE_3("烟雾报警器",3),
    DEVICE_TYPE_4("智能门锁",4),
    OTHER("",5);

    private final String name;
    private final Integer code;

    public static DeviceType parse(Integer code) {
        List<DeviceType> filtered = Arrays.stream(DeviceType.values())
                .filter(item -> Objects.equals(item.getCode(), code))
                .collect(Collectors.toList());
        return CollectionUtils.isEmpty( filtered ) ? OTHER : filtered.get(0);
    }
}